<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>注册</span>
    </div>
    <el-input v-model="username" placeholder="请输入账号" class="input-css" name="username"></el-input>
    <el-input v-model="password" placeholder="请输入密码" class="input-css" name="password" type="password"></el-input>
    <el-button type="primary" class="input-css" @click="addUser">立即注册</el-button>
  </el-card>
</template>

<script>
export default {
  name: 'register',
  data () {
    return {
      username: '',
      password: '',
      userInfo: {}
    }
  },
  methods: {
    addUser () {
      var userName = this.username;
      var passWord = this.password;
      this.$axios.post('/api/user/addUser', {
        username:userName,
        password:passWord
      })
      .then((res) => {
        console.log(res)
        if(res.status == 200){
            if(!res.data.msg){
              this.$router.push({
                path: '/login'
              })
            } else {
              this.userMsg = res.data.msg
            }
          }
      })
      .catch((err) => {
        console.log(err)
      })
    }
  }
}
</script>

<style>
.box-card{
  width: 20%;
  height:280px;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform:translate(-50%,-50%);
  box-sizing: border-box;
}
.input-css{
  margin:10px 0;
}

</style>
